package com.ruoyi.message.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.message.domain.AlgsMessage;
import com.ruoyi.message.service.IAlgsMessageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 站内信Controller
 * 
 * @author ruoyi
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/message")
public class AlgsMessageController extends BaseController
{
    @Autowired
    private IAlgsMessageService algsMessageService;

    /**
     * 查询站内信列表
     */
//    @RequiresPermissions("message:message:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsMessage algsMessage)
    {
        startPage();
        List<AlgsMessage> list = algsMessageService.selectAlgsMessageList(algsMessage);
        return getDataTable(list);
    }

    /**
     * 导出站内信列表
     */
//    @RequiresPermissions("message:message:export")
//    @Log(title = "站内信", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsMessage algsMessage)
    {
        List<AlgsMessage> list = algsMessageService.selectAlgsMessageList(algsMessage);
        ExcelUtil<AlgsMessage> util = new ExcelUtil<AlgsMessage>(AlgsMessage.class);
        util.exportExcel(response, list, "站内信数据");
    }

    /**
     * 获取站内信详细信息
     */
//    @RequiresPermissions("message:message:query")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(algsMessageService.selectAlgsMessageByMessageId(messageId));
    }

    /**
     * 新增站内信
//     */
//    @RequiresPermissions("message:message:add")
//    @Log(title = "站内信", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsMessage algsMessage)
    {
        return toAjax(algsMessageService.insertAlgsMessage(algsMessage));
    }

    /**
     * 修改站内信
     */
//    @RequiresPermissions("message:message:edit")
//    @Log(title = "站内信", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsMessage algsMessage)
    {
        return toAjax(algsMessageService.updateAlgsMessage(algsMessage));
    }

    /**
     * 删除站内信
     */
//    @RequiresPermissions("message:message:remove")
//    @Log(title = "站内信", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(algsMessageService.deleteAlgsMessageByMessageIds(messageIds));
    }
}
